{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.read_csv('FE_boston_housing.csv')\n",
    "train.head()\n",
    "\n",
    "\n",
    "y = train['MEDV']\n",
    "X = train.drop(['MEDV','log_MEDV'],axis=1)\n",
    "feature_names = X.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OLS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZMAAAD4CAYAAAApWAtMAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3df7hdZXnm8e8tCoIRUJHfQirFoFJM9Oi0l6LBoKIiFos2UazMaNFBmg4YKhaYoThIgVoqTaqotYIzEoUaQYrYGKDEKUFOSAADogIKiJIIFbVE+XXPH+s9stk5Z599zv61dnJ/rmtf2Wutd6/17HDIc9Z63/d5ZZuIiIhOPGXQAURExPBLMomIiI4lmURERMeSTCIiomNJJhER0bGnDjqAfthpp508c+bMQYcRETE0Vq9e/TPbz223/RaRTGbOnMno6Oigw4iIGBqSfjSV9nnMFRERHdsi7kwiNjczT/yXQYcQQ+CHf/3mvl1rSncmkh6TtFbSdyR9TdKOTcePk/RrSTs07Jsr6UFJayTdJukaSYdOcp3jJd0i6SZJKyTt3XR8e0k/lrR4KvFHRERvTPUx10bbs23vDzwAfLDp+ALgeuDwpv0rbc+xPQtYCCyWNK/FddYAI7YPAC4Gzmo6/lHg36YYe0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\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the r2 of OLS is  0.7892379817042661\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import LinearRegression\n",
    "lr = LinearRegression()\n",
    "lr.fit(X,y)\n",
    "y_pre_lr = lr.predict(X)\n",
    "\n",
    "coefs = pd.Series(lr.coef_,index=feature_names)\n",
    "img_coefs = pd.concat([coefs.sort_values().head(10),coefs.sort_values().tail(10)])\n",
    "img_coefs.plot(kind ='barh')\n",
    "plt.show()\n",
    "\n",
    "from sklearn.metrics import r2_score\n",
    "r2_lr =  r2_score(y,y_pre_lr)\n",
    "print('the r2 of OLS is ',r2_lr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "从图中可以看出来，波士顿房价与高速公路的便利、住宅的数目数强相关。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ridge"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAD4CAYAAAD7CAEUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3df7hcVX3v8fdHFAQjoCK/hVTEoFJM9OhtH0XBoKIiFos2Uaz0atGLNL1gqNhAb0ovUqCWikkVtVbwXomGiiBFbAxY4y0gJySABFEBBURJhIpaokD43D/2OjCZzJkzk8zsM5PzeT3PeTJ77zV7f+ccON+z91rru2SbiIiITj1psgOIiIjhksQRERFdSeKIiIiuJHFERERXkjgiIqIrT57sAOqwyy67ePr06ZMdRkTE0Fi5cuXPbT+71b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T399B2So5ERER38qgqIiK6ksQRERFdSeKIiIiuJHFERERXkjgiIqIrSRwREdGVJI6IiOjK/wcYpuH2fhOcBQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the r2 of Ridge is  0.7891619682681157\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import Ridge\n",
    "ridge = Ridge()\n",
    "ridge.fit(X,y)\n",
    "\n",
    "y_pre_ridge = ridge.predict(X)\n",
    "\n",
    "coefs = pd.Series(ridge.coef_,index=feature_names)\n",
    "img_coefs = pd.concat([coefs.sort_values().head(10),coefs.sort_values().tail(10)])\n",
    "img_coefs.plot(kind ='barh')\n",
    "plt.show()\n",
    "\n",
    "from sklearn.metrics import r2_score\n",
    "r2_ridge =  r2_score(y,y_pre_ridge)\n",
    "print('the r2 of Ridge is ',r2_ridge)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lasso"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAD4CAYAAAD7CAEUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nO3df7hcVX3v8fdHFAQjoCK/hVTEoFJM9OhtH0XBoKIiFos2Uaz0atGLNL1gqNhAb0ovUqCWikkVtVbwXomGiiBFbAxY4y0gJySABFEBBURJhIpaokD43D/2OjCZzJkzk8zsM5PzeT3PeTJ77zV7f+ccON+z91rru2SbiIiITj1psgOIiIjhksQRERFdSeKIiIiuJHFERERXkjgiIqIrT57sAOqwyy67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gO4r+G/u8sGLL6PAbeU2K4GXlT399B2So5ERER38qgqIiK6ksQRERFdSeKIiIiuJHFERERXkjgiIqIrSRwREdGVJI6IiOjK/wcYpuH2fhOcBQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the r2 of Lasso is 0.7891619682681157\n"
     ]
    }
   ],
   "source": [
    "from sklearn.linear_model import Lasso\n",
    "lasso = Ridge()\n",
    "lasso.fit(X,y)\n",
    "y_pre_lasso = lasso.predict(X)\n",
    "\n",
    "coefs = pd.Series(lasso.coef_,index=feature_names)\n",
    "img_coefs = pd.concat([coefs.sort_values().head(10),coefs.sort_values().tail(10)])\n",
    "img_coefs.plot(kind ='barh')\n",
    "plt.show()\n",
    "\n",
    "from sklearn.metrics import r2_score\n",
    "r2_lasso = r2_score(y,y_pre_lasso)\n",
    "print('the r2 of Lasso is',r2_lasso)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 修改标准化MinMaxScaler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "train = pd.read_csv('FE_mm_boston_housing.csv')\n",
    "train.head()\n",
    "y = train['MEDV']\n",
    "X = train.drop(['MEDV','log_MEDV'],axis=1)\n",
    "feature_names = X.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### OLS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAD4CAYAAAD7CAEUAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90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YxPpggRtvrbW9ne4btGVT9RH1JGo0A8tP5iIdnA8uo/mNaBmxb9s+mWlgK4LXAdVSjIa4DDh3CGN8FPAysqv3MGpb4yvZyYC2wgeq3sNf1IbY3ALdQ9RqQVskAAAB8SURBVPccU/YdT/U/JsDTgHOAHwFXAb/b53+3E8X3kvJn9d/AOmBNP+NrM8Z/B+6u/Xd3wZDF91lgTYntEuCFw/Zn2NT2Uvo4qiolRyIioiN5VRURER1J4oiIiI4kcUREREeSOCIioiNJHBER0ZEkjoiI6EgSR0REdOR/AFfRksC0FDM3AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the r2 of OLS is  0.7892379817042661\n"
     ]
    }
   ],
   "source": [
    "#OLS\n",
    "from sklearn.linear_model import LinearRegression\n",
    "lr = LinearRegression()\n",
    "lr.fit(X,y)\n",
    "y_pre_lr = lr.predict(X)\n",
    "\n",
    "coefs = pd.Series(lr.coef_,index=feature_names)\n",
    "img_coefs = pd.concat([coefs.sort_values().head(10),coefs.sort_values().tail(10)])\n",
    "img_coefs.plot(kind ='barh')\n",
    "plt.show()\n",
    "\n",
    "from sklearn.metrics import r2_score\n",
    "r2_lr =  r2_score(y,y_pre_lr)\n",
    "print('the r2 of OLS is ',r2_lr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Ridge"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAD4CAYAAADCb7BPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgA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ZinUawpf47t83sY21jGjXlAXA3sKekF5d/hXIrY69V/l8OBy1z2QvZJOzEPonHjLh+tnAkcZnsQfuloJ1rutAgAAADbSURBVOY96zbfCPyih/E10zJm2/fZ3t72DBdLZSyn+PseM3nUTpzyL4pn10sp/iMvBbYr9w8BXy/fvw64jmL0wnXAMZMg5iOAR4CVda9Zgxxzub0MWAdsoPjN6fV9iPUNwE0UfUYnlPs+Wf5PBfAM4Hzgl8BPgRf2899DmzHvX/59/jewHljT75jbjPvfgbvq/g1fNAli/gKwpoz3cuAlgx5zQ9sraGMUVkqZRERER/IIKyIiOpIEEhERHUkCiYiIjiSBRERER5JAIiKiI0kgERHRkSSQiIjoyP8H4EWqwgsxpKIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the r2 of Ridge is  0.7859795753626868\n"
     ]
    }
   ],
   "source": [
    "#Ridge\n",
    "from sklearn.linear_model import Ridge\n",
    "ridge = Ridge()\n",
    "ridge.fit(X,y)\n",
    "\n",
    "y_pre_ridge = ridge.predict(X)\n",
    "\n",
    "coefs = pd.Series(ridge.coef_,index=feature_names)\n",
    "img_coefs = pd.concat([coefs.sort_values().head(10),coefs.sort_values().tail(10)])\n",
    "img_coefs.plot(kind ='barh')\n",
    "plt.show()\n",
    "\n",
    "from sklearn.metrics import r2_score\n",
    "r2_ridge =  r2_score(y,y_pre_ridge)\n",
    "print('the r2 of Ridge is ',r2_ridge)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Lasso"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZAAAAD4CAYAAADCb7BPAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh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kNfUPUrul4n+XS8EvlxpROMbL+ZnUSzyd0X5JHYn4CJJh9keGeuieYRVuIhNvx0cCVzY2EDSrpK2LN8/B3glcGPPIhytnZinUawpf47t83sY21jGjXlAXA3sKekF5d/hXIrY69V/l8OBy1z2QvZJOzEPonHjLh+tnAkcZnsQfuloJ1rutAgAAADbSURBVOY96zbfCPyih/E10zJm2/fZ3t72DBdLZSyn+PseM3nUTpzyL4pn10sp/iMvBbYr9w8BXy/fvw64jmL0wnXAMZMg5iOAR4CVda9Zgxxzub0MWAdsoPjN6fV9iPUNwE0UfUYnlPs+Wf5PBfAM4Hzgl8BPgRf2899DmzHvX/59/jewHljT75jbjPvfgbvq/g1fNAli/gKwpoz3cuAlgx5zQ9sraGMUVkqZRERER/IIKyIiOpIEEhERHUkCiYiIjiSBRERER5JAIiKiI0kgERHRkSSQiIjoyP8H4EWqwgsxpKIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the r2 of Lasso is 0.7859795753626868\n"
     ]
    }
   ],
   "source": [
    "#Lasso\n",
    "from sklearn.linear_model import Lasso\n",
    "lasso = Ridge()\n",
    "lasso.fit(X,y)\n",
    "y_pre_lasso = lasso.predict(X)\n",
    "\n",
    "coefs = pd.Series(lasso.coef_,index=feature_names)\n",
    "img_coefs = pd.concat([coefs.sort_values().head(10),coefs.sort_values().tail(10)])\n",
    "img_coefs.plot(kind ='barh')\n",
    "plt.show()\n",
    "\n",
    "from sklearn.metrics import r2_score\n",
    "r2_lasso = r2_score(y,y_pre_lasso)\n",
    "print('the r2 of Lasso is',r2_lasso)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 结果对比\n",
    "| type | StandardScaler | MinMaxScaler |\n",
    "|---|---|  ---|\n",
    "|OLS|0.7892379817042661|0.7892379817042661  |\n",
    "|Ridge| 0.7891619682681157|0.7859795753626868|\n",
    "|Lasso|0.7891619682681157|0.7859795753626868|"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
